/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package colloque.servlets;

import colloque.Colloque;
import colloque.Expose;
import colloque.forms.ExposeForm;
import colloque.helpers.ColloqueHelper;
import colloque.helpers.InstitutionHelper;
import colloque.helpers.SecurityHelper;
import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Thomas
 */
public class CreerExpose extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        SecurityHelper security = new SecurityHelper(request.getSession());
        if (security.isAuthenticated() == false) {
            response.sendRedirect("Connexion");
        } else {
            if (request.getParameter("colloqueid") != null) {
                int Colid = Integer.parseInt(request.getParameter("colloqueid"));
                try {
                    ColloqueHelper colloquehelper = new ColloqueHelper();
                    InstitutionHelper institutionhelper = new InstitutionHelper();
                    Colloque colloque = (Colloque) colloquehelper.getColloqueById(Colid);
                    request.setAttribute("colloque", colloque);
                    List institutions = institutionhelper.getallinstitution();
                    request.setAttribute("institutions", institutions);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                ColloqueHelper colloquehelper = new ColloqueHelper();
                request.setAttribute("colloques", colloquehelper.getColloques());
            }
            RequestDispatcher distpacher = request.getRequestDispatcher("/jsp/CreerExpose.jsp");
            distpacher.forward(request, response);
        }
    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            ExposeForm exposeform = new ExposeForm();
            Expose oexpo = exposeform.creerExposeConnecte(request);
            request.setAttribute("oexpo", oexpo);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            this.getServletContext().getRequestDispatcher("/jsp/CreerColloqueSuccess.jsp").forward(request, response);
        }
    }
}
